<template>
	<view>
		<van-nav-bar title="浏览记录" left-text="返回" left-arrow @click-left="onClickLeft" />
		<view class="box">
			<view v-show="Pitera" style="margin: 100px auto;">
				<van-empty description="暂无记录" />
			</view>
			<view  class="goods" v-for="(item,index) in MyCookies" :key="index">
				<view class="">
					<img @click="jump(item)" style="width: 320rpx;height: 320rpx;border-radius:5%;margin-left: 10rpx;" :src="item.commodityImg" alt="">
				</view>
				<view style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;font-weight: bold;">
					{{item.commodityName}}
				</view>
				<view style="width: 350rpx;">
					<span style="color: red;font-weight: bold;">￥{{item.currentPrice}}</span>
					<span style="text-decoration: line-through;margin-left: 100rpx;color: gray;">￥{{item.originalPrice}}</span>
				</view>
				<view >
					<button @click="deleteMyCookies(item.browseId)" style="height: 30px;line-height:30px;background-color: darkgrey;color:aliceblue">删除记录</button>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../com/request.js'
	export default {
		data() {
			return {
				MyCookies:[],
				Pitera:true
			}
		},
		methods: {
			onClickLeft() {
				uni.redirectTo({
					url: '/pages/MyCenter/MyCenter'
				});
			  },
			selectCookies(){
				request({
						url:'api/BrowseHistory/get',
						methods:'get',
						data:{
						  acc:uni.getStorageSync("userTel")
						},
						success: (resp) => {
							this.MyCookies=resp.data.data
							if(this.MyCookies.length>0){
								this.Pitera=false
							}else{
								this.Pitera=true
							}
							console.log(this.MyCookies,48);
						}
					})
			},
			deleteMyCookies(browseId){
				request({
						url:'api/delBrowseHistory/get',
						methods:'get',
						data:{
						  browseId:browseId
						},
						success: (resp) => {
							console.log(resp,69);
							this.selectCookies()
						}
					})
			},
			jump(item){
				uni.setStorageSync('hx220408commodityId',item.commodityId)
				uni.setStorageSync('hx220408userTel',item.userTel)
				uni.redirectTo({
					url: '/pages/goods/goods'
				})
			}
		},
		onLoad(){
			this.selectCookies()
		}
	}
</script>

<style>
.goods{
	width: 350rpx;
	margin-left: 22rpx;
	margin-top: 15px;
}
.box{
	display:flex;
	flex-wrap: wrap;
}
</style>
